<?php

namespace app\api\dao;

use app\api\model\User;

class UserDao extends BaseDao
{
    public function getByUsername(string $username): User
    {
        return User::where('username', $username)->find();
    }

    public function existByUsername(string $username): bool
    {
        return User::where('username', $username)->isExists();
    }

    public function add(string $username, string $password): User
    {
        return User::create([
            'username' => $username,
            'password' => password_hash($password, PASSWORD_DEFAULT),
        ]);
    }


}
